﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace windows.实验一
{
        class Class7
        {
            #region .对整型数组{20,16,78,61,12,99,57,34,8}进行冒泡排序，要求数据由小到大排列。
            static void Main(string[] args)
            {
                int[] data = new int[] { 20, 16, 78, 61, 12, 99, 57, 34, 8 };
                int[] data1;
                data1 = MaoPao(data);
                for (int i = 0; i < data1.Length; i++)
                {
                    Console.Write(data1[i].ToString()+" ");
                }
                Console.ReadKey();
            }

            private static int[] MaoPao(int[] data)
            {
                int count = 0;
                while (count != data.Length-1)
                {
                    for (int i = 0; i < data.Length-1-count; i++)
                    {
                        if (data[i] > data[i+1])
                        {
                            data[i] = data[i] + data[i + 1];
                            data[i + 1] = data[i] - data[i + 1];
                            data[i] = data[i] - data[i + 1];
                        }
                    }
                    count++;
                }
                return data;
            }
            #endregion
        }
}
